<template>
  <div>
    <el-form ref="form" :model="form2" label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="申请ID"> <span>{{ form2.applyId }}</span> </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请状态"> <span>{{ selectDictLabel(statusOptions,form2.status) }}</span> </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="申请者"> <span>{{ form2.userName }}</span> </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="原请假天数"> <span>{{ form2.leaveDays }}</span> </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="申请时间"> <span>{{ form2.createTime }}</span> </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="更新时间"> <span>{{ form2.updateTime }}</span> </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="重新申请天数">
        <el-input-number v-model="form2.leaveDays" :min="1" :max="10" label="请假天数"></el-input-number>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form2.remark" placeholder="请输入备注" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="resubmit" v-loading.fullscreen.lock="loading">重新申请</el-button>
        <el-button type="danger" @click="resubmit" v-loading.fullscreen.lock="loading">作废</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { selectById,restartWfInstance } from "@samples/api/samples/leave";

export default {
  name: "ResubmitPage",
  props: {
    approveObject: Object,
    buttons: Array,
  },
  data() {
    return {
      loading: false,
      // 审批状态的数据字典选项列表：samples_leave_status
      statusOptions: [],
      form2: {},
    }
  },
  created() {
    this.init();

    // 获取数据字典：samples_leave_status
    this.getDicts("samples_leave_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    init() {
      const applyId = this.approveObject.businessKey;
      selectById(applyId).then(response => {
        this.form2 = response.data;
        this.form2.oldLeaveDays = response.data.leaveDays;
      });
    },
    resubmit() {
      const params = {
        ...this.form2,
        params:{
          taskId: this.approveObject.taskId 
        }
      };
      restartWfInstance(params).then(response => {
        if (response.data === true) {
          this.msgSuccess("重新提交成功");
          // 触发关闭事件来关闭窗口
          // 参数1：固定值，close
          // 参数2: 可以自定义，查看/task/todo/index.vue中applyCloseHandler用途
          // 参数3：将提交后台的参数传递出去，目前还没有使用该值   
          this.$emit("close", "reApply", params);
        } else {
          this.msgError("重新提交失败");
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
</style>